<template>
	<view>
		<view style="width:750upx;height:150upx;line-height:150upx;text-align:center;">拍摄/上传您的头像</view>
		
		<view class="photo_head">
			<view @tap="headavatar()" class="bg_img_h" style="position:relative;">
				<image src="../../static/camera.png"></image>
				<view>点击拍摄/上传您的头像</view>
				<image style="position:absolute;top:0;left:0;width:100%;height:100%;" v-if="urlavatar" :src="urlavatar"></image>
			</view>
		</view>
		<!-- <view class="submit" @click="submit()">
			<view>提交</view>
		</view> -->
	</view>
</template>

<script>
	import request from '@/common/lib/request.js'
	export default {
		data() {
			return {
				baseUrl:request.common.baseUrl,
				urlavatar:''
			}
		},
		onLoad:function(option){
			this.urlavatar=option.avatar
		},
		methods: {
			headavatar(){
				var that=this
				uni.chooseImage({
					count: 1,
					sizeType:['copressed'],
					success(res) {
						that.urlavatar=res.tempFilePaths[0]
						uni.setStorageSync('keyHeadavatar',res.tempFilePaths[0])
						//因为有一张图片， 输出下标[0]， 直接输出地址
						var imgFiles = res.tempFilePaths[0]
						// 上传图片
						// 做成一个上传对象
						var uper = uni.uploadFile({
							// 需要上传的地址
							url:that.baseUrl+'/api/users/wuploadtmd?openid='+uni.getStorageSync('keyOpenid'),
							// filePath  需要上传的文件
							filePath: imgFiles,
							name: 'file',
							success(res1) {
								// 显示上传信息
								console.log(res1)
							}
						});
					}
				})
			},
			submit(){
				uni.navigateBack({
					delta: 1
				})
			}
			
		}
	}
</script>

<style>
page{
	background-color: #ffffff;
}
.photo_head{
	width:450upx;
	height:250upx;
	padding:25upx 150upx;
}
.bg_img_h{
	width:450upx;
	height:250upx;
	background-image:url('../../static/head.png');
	background-size:450upx 250upx;
	text-align:center;
}
.bg_img_h image{
	width:80upx;
	height:80upx;
	margin-top:45upx;
	margin-bottom:10upx;
}
.photo_emblem{
	width:450upx;
	height:250upx;
	padding:25upx 150upx;
}
.bg_img_e{
	width:450upx;
	height:250upx;
	background-image:url('../../static/emblem.png');
	background-size:450upx 250upx;
	text-align:center;
}
.bg_img_e image{
	width:80upx;
	height:80upx;
	margin-top:45upx;
	margin-bottom:10upx;
}
.submit{
	margin-top:50upx;
	text-align:center;
}
.submit view{
	background-color:#ff6101;
	color:#FFFFFF;
	font-size:28upx;
	width:650upx;
	height:60upx;
	line-height:60upx;
	margin:auto;
	border-radius:30upx;
}
</style>
